package com.g0dkar.leet.persistence;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;

/**
 * Represents a Persistence Manager: a class who manages all generic DAO stuff like saves, searches and listings.
 * 
 * @author g0dkar
 * 
 */
public interface PersistenceManager {
	/**
	 * Saves a object
	 * 
	 * @param obj
	 *            - Object to be saved (must be a {@link Serializable} object)
	 * @throws Exception
	 *             Something went wrong
	 */
	public void save(Serializable obj) throws Exception;
	
	/**
	 * Find a ClassMapping Object by it's ID field (must be a numerical index)
	 * 
	 * @param <T>
	 *            - The Object Type
	 * @param id
	 *            - The Object ID
	 * @param klass
	 *            - The Object Type
	 * @return The found Object, or <code>null</code> if it wasn't found
	 * @throws Exception
	 *             Something went wrong.
	 */
	public <T> T findById(Long id, Class<T> klass) throws Exception;
	
	/**
	 * Find all the persisted ClassMapping Objects of a single {@link Class type}.
	 * 
	 * @param <T>
	 *            - The Object Type
	 * @param klass
	 *            - The Object Type
	 * @return All the Objects of that type on the persistence base, or <code>null</code> if nothing was found
	 * @throws Exception
	 *             Something went wrong.
	 */
	public <T> Collection<T> findAll(Class<T> klass) throws Exception;
	
	/**
	 * Find all of the persisted ClassMapping Objects of a single {@link Class type} that match the especified
	 * parameters.
	 * 
	 * @param <T>
	 *            - The Object Type
	 * @param params
	 *            - The parameter map: Key = The object's field to be match, Value = Value to which it'll be matched
	 * @param klass
	 *            - The Object Type
	 * @return All the Objects of that type on the persistence base that matches the especified parameters, or
	 *         <code>null</code> if nothing was found.
	 * @throws Exception
	 *             Something went wrong.
	 */
	public <T> Collection<T> findByParams(Map<String, Object> params, Class<T> klass) throws Exception;
}
